﻿#include <algorithm>
#include <gtest/gtest.h>
#include <iostream>
#include <vector>

#include <learn/alg/alg_common_surface.h>

using namespace xi;
using namespace xi::alg;

TEST(TestCommonSurface, bilinear)
{
    auto sur = Alg_Surface_Common<3>::bilinear(Vec3{0.0, 0.0, 0.0}, Vec3{1.0, 0.0, 1.0}, Vec3{1.0, 1.0, 0.0},
                                               Vec3{0.0, 1.0, 1.0});
}

TEST(TestCommonSurface, cylinder)
{
    auto curve = Geom_QR_BSplineCurve<3>::make_circle(Vec3{0.0, 0.0, 0.0}, Vec3{0.0, 0.0, 1.0}, Vec3{1.0, 0.0, 0.0}, 10,
                                                      45.0, 405.0);
    auto sur = Alg_Surface_Common<3, true>::cylinder(curve, Vec3{0.0, 10.0, 0.0});

    std::vector<Vec3> ccpts = {Vec3{0.0, 0.0, 0.0}, Vec3{1.0, 0.0, 1.0}, Vec3{2.0, 0.0, 0.0}};
    std::vector<double> knots = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0};
    auto curve2 = std::make_shared<Geom_BSplineCurve<3>>(std::move(ccpts), std::move(knots), 2);
    auto sur2 = Alg_Surface_Common<3>::cylinder(curve2, Vec3{0.0, 10.0, 0.0});
}

TEST(TestCommonSurface, ruled)
{
    std::vector<Vec3> ccpts = {Vec3{0.0, 0.0, 0.0}, Vec3{1.0, 0.0, 1.0}, Vec3{2.0, 0.0, 0.0}};
    std::vector<double> knots = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0};
    auto c = std::make_shared<Geom_BSplineCurve<3>>(std::move(ccpts), std::move(knots), 2);
    c->insert_knot(0.5);

    std::vector<Vec3> dcpts = {Vec3{0.0, 1.0, 0.0}, Vec3{0.0, 1.0, 1.0}, Vec3{2.0, 1.0, 1.0}, Vec3{2.0, 1.0, 0.0}};
    std::vector<double> dknots = {0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0};
    auto d = std::make_shared<Geom_BSplineCurve<3>>(std::move(dcpts), std::move(dknots), 3);

    auto sur = Alg_Surface_Common<3>::ruled(c, d);
}

TEST(TestCommonSurface, revolution)
{
    auto curve = Geom_QR_BSplineCurve<3>::make_circle(Vec3{0.0, 0.0, 0.0}, Vec3{0.0, 0.0, 1.0}, Vec3{1.0, 0.0, 0.0}, 10,
                                                      0.0, 180.0);
    auto sur = Alg_Surface_Common<3, true>::revolution(curve, Vec3{0.0, 0.0, 1.0}, Vec3{0.0, 0.0, 1.0}, 360);

    std::vector<Vec3> ccpts = {Vec3{0.0, 0.0, 0.0}, Vec3{1.0, 0.0, 1.0}, Vec3{2.0, 0.0, 0.0}};
    std::vector<double> knots = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0};
    auto curve2 = std::make_shared<Geom_BSplineCurve<3>>(std::move(ccpts), std::move(knots), 2);
    auto sur2 = Alg_Surface_Common<3>::revolution(curve2, Vec3{0.0, 0.0, 1.0}, Vec3{0.0, 0.0, 1.0}, 360);
}